package com.zsxb.crm.mapper;

import com.zsxb.crm.annotation.AutoFill;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.MenuPageDTO;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.pojo.Menu;
import com.zsxb.crm.vo.MenuTrees;
import com.zsxb.crm.vo.MenuVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MenuMapper {

    /**
     * 菜单管理分页查询
     */
    List<Menu> queryAll(MenuPageDTO menuPageDTO);

    /**
     * 菜单栏新增
     */

   @Insert("insert into sys_menu (menu_id,menu_name,parent_id,order_num,path,component,is_frame,is_cache," +
           "menu_type,visible,status,perms,icon,create_by,create_time,update_by,update_time,remark)" +
           "values" +
           "(#{menuId},#{menuName},#{parentId},#{orderNum},#{path},#{component},#{isFrame},#{isCache}," +
           "#{menuType},#{visible},#{status},#{perms},#{icon},#{createBy},#{createTime},#{updateBy},#{updateTime},#{remark})")
   @AutoFill(OperationType.INSERT)
    void add(Menu menu);

    /**
     * 菜单栏删除
     */

   @Delete("delete from sys_menu where menu_id = #{menuId}")
    void deleteByMenuId(Long menuId);

    /**
     * 根据id查询菜单栏详情
     */
    @Select("select * from sys_menu where menu_id = #{menuId} ")
    MenuVO queryByMenuId(Long menuId);

    /**
     * 菜单修改
     */

    @AutoFill(OperationType.UPDATE)
    void update(Menu menu);

    @Select("select * from sys_menu where path = #{s}")
    Menu queryByPath(String s);


    /**
     * 查询所有菜单
     * @return
     */
    List<MenuTrees> queryAllMenu();
}
